package program02;

import org.w3c.dom.ls.LSOutput;

/**
 * @version 1.0
 * @since:
 * @ClassName:Victory
 * @author: Li Jiahui
 * @date: 2021-01-09 17:11
 */
public class Victory {
    void win(){
        //从数组中的元素有棋子时，判断横向的累加和是否等于5，如果是5，就表示这一方胜利
        for (int i = 0 ; i < 11 ; i ++) {
            for (int j = 0; j < 11; j++) {
                if (DrawChessBoard.chessBoard[i][j] == "B")
                {
                    int bv = 1;
                    for (int k = 1; k <= 5; k++)
                    {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i][j+k]) bv +=1;
                    }
                    if (bv == 5) {System.out.println("黑方胜"); break;}
                }
                if (DrawChessBoard.chessBoard[i][j] == "W") {
                    int wv = 1;
                    for (int k = 1; k <= 5; k++) {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i][j+k]) wv += 1;
                    }
                    if (wv == 5) {System.out.println("白方胜"); break;}
                }
            }
        }
        //从数组中的元素有棋子时，判断纵向的累加和是否等于5，如果是5，就表示这一方胜利
        for (int i = 0 ; i < 11 ; i ++) {
            for (int j = 0; j < 11; j++) {
                if (DrawChessBoard.chessBoard[j][i] == "B")
                {
                    int bv = 1;
                    for (int k = 1; k <= 5; k++)
                    {
                        if (DrawChessBoard.chessBoard[j][i] == DrawChessBoard.chessBoard[j+k][i]) bv +=1;
                    }
                    if (bv == 5) {System.out.println("黑方胜"); break;}
                }
                if (DrawChessBoard.chessBoard[i][j] == "W") {
                    int wv = 1;
                    for (int k = 1; k <= 5; k++) {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i][j+k]) wv += 1;
                    }
                    if (wv == 5) {System.out.println("白方胜"); break;}
                }
            }
        }
        //从数组中的元素有棋子时，判断右斜的累加和是否等于5，如果是5，就表示这一方胜利
        for (int i = 0 ; i < 11 ; i ++) {
            for (int j = 0; j < 11; j++) {
                if (DrawChessBoard.chessBoard[i][j] == "B")
                {
                    int bv = 1;
                    for (int k = 1; k <= 5; k++)
                    {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i+k][j+k]) bv +=1;
                    }
                    if (bv == 5) {System.out.println("黑方胜"); break;}
                }
                if (DrawChessBoard.chessBoard[i][j] == "W") {
                    int wv = 1;
                    for (int k = 1; k <= 5; k++) {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i+k][j+k]) wv += 1;
                    }
                    if (wv == 5) {System.out.println("白方胜"); break;}
                }
            }
        }
        //从数组中的元素有棋子时，判断左斜的累加和是否等于5，如果是5，就表示这一方胜利
        for (int i = 15 ; i > 4 ; i--) {
            for (int j = 15; j > 4; j--) {
                if (DrawChessBoard.chessBoard[i][j] == "B")
                {
                    int bv = 1;
                    for (int k = 1; k <= 5; k++)
                    {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i-k][j-k]) bv +=1;
                    }
                    if (bv == 5) {System.out.println("黑方胜"); break;}
                }
                if (DrawChessBoard.chessBoard[i][j] == "W") {
                    int wv = 1;
                    for (int k = 1; k <= 5; k++) {
                        if (DrawChessBoard.chessBoard[i][j] == DrawChessBoard.chessBoard[i-k][j-k]) wv += 1;
                    }
                    if (wv == 5) {System.out.println("白方胜"); break;}
                }
            }
        }
    }

}
